﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace Emz.Core.Models
{
    public class PayrollSummary :EntityBase<int>
    {
        public int EmployeeId { get; set; }
        public int PayRollId { get; set; }

        public virtual Employee Employee { get; set; }
        public virtual PayrollDate PayRoll { get; set; }

        public double RegularHours { get; set; }
        public double LegalHours { get; set; }
        public double SpecialHours { get; set; }        
        public double OverTime { get; set; }
        public double OverTimeLegal { get; set; }
        public double OverTimeSpecial { get; set; }
        public double NightDiff { get; set; }
        public double NightDiffLegal { get; set; }
        public double NightDiffSpecial { get; set; }
        public double CoverUpHours { get; set; }

        #region Rates
        [NotMapped]
        public double RatePerHour
        {
            get
            {
                return Employee.Detachment.RatePerHour;
            }
        }
        [NotMapped]
        public double RatePerHourLegal
        {
            get
            {
                return RatePerHour * Employee.Detachment.Client.LegalHoliday / 100;
            }
        }
        [NotMapped]
        public double RatePerHourSpecial
        {
            get
            {
                return  RatePerHour * Employee.Detachment.Client.SpecialHoliday / 100;
            }
        }
        [NotMapped]
        public double RatePerHourRegularOverTime
        {
            get
            {
                return RatePerHour * Employee.Detachment.Client.RegularOverTime / 100;
            }
        }
        [NotMapped]
        public double RatePerHourSpecialOverTime
        {
            get
            {
                return RatePerHour * Employee.Detachment.Client.SpecialOverTime / 100;
            }
        }
        [NotMapped]
        public double RatePerHourNightDiff
        {
            get
            {
                return RatePerHour * Employee.Detachment.Client.NightDiff / 100;
            }
        }

        #endregion

        #region Computations
        [NotMapped]
        public double RegularHoursPay { get { return RegularHours * RatePerHour; } }
        [NotMapped]
        public double LegalHoursPay { get { return LegalHours * RatePerHourLegal; } }
        [NotMapped]
        public double SpecialHoursPay { get { return SpecialHours * RatePerHourSpecial; } }
        [NotMapped]
        public double OverTimePay { get { return OverTime * RatePerHourRegularOverTime; } }
        [NotMapped]
        public double OverTimeLegalPay { get { return OverTimeLegal * RatePerHourLegal; } }
        [NotMapped]
        public double OverTimeSpecialPay { get { return OverTimeSpecial * RatePerHourSpecialOverTime; } }
        [NotMapped]
        public double NightDiffPay { get { return NightDiff * RatePerHourNightDiff; } }
        [NotMapped]
        public double NightDiffLegalPay { get { return NightDiffLegal * RatePerHourLegal; } }
        [NotMapped]
        public double NightDiffSpecialPay { get { return NightDiffSpecial * RatePerHourSpecial; } }
        [NotMapped]
        public double CoverUpHoursPay { get { return CoverUpHours * RatePerHour; } }
        [NotMapped]
        public double GrossPay 
        { 
            get 
            {
                return RegularHoursPay + 
                    LegalHoursPay + 
                    SpecialHoursPay + 
                    OverTimePay + 
                    OverTimeLegalPay + 
                    OverTimeSpecialPay + 
                    NightDiffPay + 
                    NightDiffLegalPay + 
                    NightDiffSpecialPay +                     
                    CoverUpHoursPay; 
            } 
        }

        #endregion
    }
}
